package com.igfd.tanmao.controller;

import com.igfd.tanmao.service.ItemsService;
import com.igfd.tanmao.utils.CommonUtils;
import com.taobao.api.ApiException;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.internal.util.WebUtils;
import com.taobao.api.request.*;
import com.taobao.api.response.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@RestController
public class TestController {

    @Autowired
    private ItemsService itemsService;

    @RequestMapping(value = "/onSale")
    public String getOnSaleItems() {

        try {
            //itemsService.addTanmaoItemsOnsaleToErp("61011081dd7cad8c14f82f792263ccea09f862e3c8e328a4032945057");
            //ItemsOnsaleGetResponse tanmaoItemsOnsale = itemsService.getTanmaoItemsOnsale("61011081dd7cad8c14f82f792263ccea09f862e3c8e328a4032945057", 1L, 500L);

            //ItemSkusGetResponse tanmaoItemSkus = itemsService.getTanmaoItemSkus("574643049748", "61011081dd7cad8c14f82f792263ccea09f862e3c8e328a4032945057");
            //itemsService.updateTanmaoItemQuantity(574967152540L,3772701477851L,1L,"61011081dd7cad8c14f82f792263ccea09f862e3c8e328a4032945057");
            //itemsService.updateTanmaoDamirDomaItemQuantity("61011081dd7cad8c14f82f792263ccea09f862e3c8e328a4032945057");
            //itemsService.getTanmaoAllOrderInfo("61011081dd7cad8c14f82f792263ccea09f862e3c8e328a4032945057");
            //addTanmaoItemsOnsaleToErp
            //System.out.println("tanmaoItemSkus" + tanmaoItemSkus.getBody());
        } catch (Exception e) {
            e.printStackTrace();
        }

        //TaobaoClient client = new DefaultTaobaoClient(CommonUtils.SERVERURL, CommonUtils.APPKEY, CommonUtils.APPSECRET);
        /*ItemsOnsaleGetRequest req = new ItemsOnsaleGetRequest();
        req.setFields("num_iid,seller_cids");
        ItemsOnsaleGetResponse rsp = null;
        try {
            rsp = client.execute(req, "61011081dd7cad8c14f82f792263ccea09f862e3c8e328a4032945057");
        } catch (ApiException e) {
            e.printStackTrace();
        }
        System.out.println(rsp.getBody());*/

        /*ItemSkusGetRequest req = new ItemSkusGetRequest();
        req.setFields("sku_id,num_iid,quantity,properties_name");
        req.setNumIids("574758757051");
        ItemSkusGetResponse rsp = null;
        try {
            rsp = client.execute(req, "61011081dd7cad8c14f82f792263ccea09f862e3c8e328a4032945057");
        } catch (ApiException e) {
            e.printStackTrace();
        }
        System.out.println(rsp.getBody());*/


        //{"num_iid":574758757051,"properties_name":"1627207:28341:颜色:黑色;20509:7190522:尺码:165\/80A","quantity":1,"sku_id":3933517147290}
        /*ItemQuantityUpdateRequest req = new ItemQuantityUpdateRequest();
        req.setNumIid(574758757051L);
        req.setSkuId(3933517147290L);
        //req.setOuterId("1234");
        req.setQuantity(1L);
        req.setType(1L);
        ItemQuantityUpdateResponse rsp = null;
        try {
            rsp = client.execute(req, "61011081dd7cad8c14f82f792263ccea09f862e3c8e328a4032945057");
        } catch (ApiException e) {
            e.printStackTrace();
        }
        System.out.println(rsp.getBody());*/

        /*Map<String,String> props=new HashMap<String,String>();

        props.put("client_id",CommonUtils.APPKEY);
        props.put("response_type","code");
        props.put("redirect_uri","http://erpadmin.igfd.group");
        props.put("state","1212");

        String s = "";

        try {
            s = WebUtils.doPost("https://oauth.taobao.com/authorize", props, 3000, 3000);
            System.out.println("s = " + s);
        } catch (IOException e) {
            e.printStackTrace();
        }*/

        return "sD";
    }
}
